package com.hjl.cn.utils;

import java.util.UUID;

/**
 * @author jialin
 * @createTime 2020-09-03
 */
public class UuidUtils {
    //sessionId
    /*String sessionId = session.getId();
    Long timestamp = System.currentTimeMillis();
    sysUserUuid.setId(timestamp + sessionId.substring(0,12));*/

    //生成id，时间戳+12位UUID
    //排序：order by mid(id , 1 , 13)  -> 取出前13个字符，根据时间排序
    //Long timestamp = System.currentTimeMillis();
    //String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);


    //获取16位UUID
    public static String getUUID(){
        return UUID.randomUUID().toString();
    }

    //获取13位时间戳+12位UUID
    public static String getTimeUUID(){
        return System.currentTimeMillis() + UUID.randomUUID().toString().replaceAll("-", "").substring(0,12);
    }
    
    //创建订单号
    public static String createOID(String gId){
        String oIdPrefix = UUID.randomUUID().toString().replaceAll("-", "").substring(0,5);
        return oIdPrefix + System.currentTimeMillis() + gId;
    }
    
    public static String createNonceStr(){
        return UUID.randomUUID().toString().replaceAll("-","").substring(0,32);
    }
}
